﻿CREATE FUNCTION [util].[ChangeDateTime]
(@RealDate DATETIME, @TimeAsInt INT)
RETURNS DATETIME
AS
BEGIN
	DECLARE @TimeAsChar char(6), @ActualTime datetime
	SET @TimeAsChar = RIGHT('00000' + ISNULL(NULLIF(CAST(@TimeAsInt AS varchar(6)),'*'),'0'),6)
	SET @ActualTime = CONVERT(
		datetime
		,(CONVERT(char(8),@RealDate,112)
			+ ' ' + LEFT(@TimeAsChar,2) + ':' + SUBSTRING(@TimeAsChar,3,2) + ':' + RIGHT(@TimeAsChar,2) + ':000')
		,126)

	RETURN(@ActualTime)
END